//
//  YWEquipmentManager.h
//  maintain
//
//  Created by 郑想 on 15/10/26.
//  Copyright © 2015年 ewin. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "YWSingleton.h"
#import "YWEquipmentTroubleRecord.h"

@class YWEquipment;
@class YWMission;
@class YWLastMaintenanceTime;
@class YWMeterProperty;
@class YWEquipmentType;
@class YWEquipmentUseMenthod;
@class YWEquipmentUseRange;
@class YWEquipmentSystemType;

@interface YWEquipmentManager : NSObject
YWSingletonH(Manager)

    /**
 *  保存设备类型字典表
 *
 *  @param equipmentRulesArray 设备类型模型数组
 */
- (BOOL)saveEquipmentTypeWithArray:(NSArray*)equipmentTypeArray;
/**
 *  子系统的设备类型
 *
 *  @return 结果
 */
- (NSArray *)allEquipmentTypeWithSystemId:(NSInteger)systemTypeId;
- (NSArray *)allEquipmentSystemType;
- (NSArray *)allEquipmentSubSystemType;
- (YWEquipmentSystemType*)equipmentSystemTypeWithEquipmentTypeId:(NSInteger)equipmentTypeId;
- (NSTimeInterval)dicEquipmentRuntimeParameterMaxCreateTime;
- (BOOL)saveRuntimeParameterWithArray:(NSArray*)runtimeParameterArray;

/**
 *  保存维保规则字典表
 *
 *  @param equipmentRulesArray 维保规则模型数组
 */
- (void)saveEquipmentRulesWithArray:(NSArray*)equipmentRulesArray;
///**
// *  保存维保类型字典表
// *
// *  @param dictMaintenanceTypesArray 维保类型模型数组
// */
//- (void)saveDictMaintenanceTypesWithArray:(NSArray*)dictMaintenanceTypesArray;
///**
// *  获取所有的维保类型
// */
//- (NSArray*)maintenanceTypes;
/**
 *  设备类型名称
 *
 *  @param equipmentId 设备类型Id
 */
- (NSString*)equipmentTypeNameWithTypeId:(NSInteger)equipmentTypeId;
/**
 *  获取设备类型表里的最大的更新时间
 *
 *  @return UpdateTime
 */
- (NSTimeInterval)dicEquipmentTypeMaxUpdateTime;
/**
 *  获取设备运行参数
 *
 *  @param  equipmentTypeId 设备类型id
 *  @param  maintenanceTypeId 维保类型id
 *
 *  @return 数组
 */
- (NSArray*)equipmentFieldsWithTypeId:(NSInteger)equipmentTypeId maintenanceTypeId:(NSInteger)maintenanceTypeId;
/**
 *  获取设备初始参数
 *
 *  @param  equipmentTypeId 设备类型id
 *
 *  @return 数组
 */
- (NSArray*)equipmentParametersWithEquipmentId:(NSString*)equipmentId;
/**
 *  判断二维码下是否有设备
 *
 *  @param qrcodeId 二维码id
 *
 *  @return 结果
 */
- (BOOL)isExistEquipmentWithQrcodeId:(NSString*)qrcodeId;
/**
 *  判断位置下是否有设备
 *
 *  @param locationId 位置id
 *
 *  @return 结果
 */
- (BOOL)isExistEquipmentWithLocationId:(NSInteger)locationId;
/**
 *  保存设备
 *
 *  @param equipmentsArray 设备模型数组
 */
- (void)saveEquipmentsWithArray:(NSArray*)equipmentsArray;
/**
 *  保存扫码时下载的设备
 *
 *  @param equipmentsArray 设备模型数组
 */
- (void)saveQrcodeEquipmentsWithArray:(NSArray*)equipmentsArray;
/**
 *  获取能源仪表扩展属性
 *
 *  @param equipmentId 设备ID
 *
 *  @return 设备模型
 */
- (YWMeterProperty *)meterPropertyWithEquipmentId:(NSString*)equipmentId;
/**
 *  获取设备数据模型
 *
 *  @param ownCode 设备自编码
 *
 *  @return 设备模型
 */
- (YWEquipment*)equipmentWithOwncode:(NSString*)ownCode;
/**
 *  获取设备模型
 *
 *  @param equipmentId 设备id
 *
 *  @return 设备数据模型
 */
- (YWEquipment*)equipmentWithId:(NSString*)equipmentId;
/**
 *  获取设备模型
 *
 *  @param equipmentId 设备id
 *
 *  @return 设备数据模型
 */
- (YWEquipmentType*)equipmentTypeWithEquipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  获取执行规则
 *
 *  @param equipmentTypeId   设备类型Id
 *  @param maintenanceTypeId 维保类型Id
 *
 *  @return 规则模型数组
 */
- (NSArray*)rulesWithEquipmentTypeId:(NSInteger)equipmentTypeId maintenanceTypeId:(NSInteger)maintenanceTypeId maintenanceCycleId:(NSInteger)maintenanceCycleId;

/**
 *  获取任务维保记录中关联的设备列表
 *
 *  @param mission 任务模型
 *
 *  @return 设备模型数组
 */
- (NSArray*)equipmentsOfMaintentanceMission:(YWMission*)mission;
/**
 *  获取设备故障原因
 *
 *  @param troubleReason 原因Id
 *
 *  @return 故障原因字符串
 */
- (NSString*)getTroubleReason:(YWMalfunctionRecordReasonId)troubleReason;
///**
// *  保存设备上一次的维保时间
// *
// *  @param lastMaintenanceTimeArray 上一次维保时间模型
// *
// *  @return 结果
// */
//- (BOOL)saveLastMaintenanceTimeWithArray:(NSArray*)lastMaintenanceTimeArray;
///**
// *  获取设备上一次的维保时间
// *
// *  @param equipmentId 设备Id
// *
// *  @return 维保时间模型
// */
//- (YWLastMaintenanceTime*)lastMaintenanceTimeWithEquipmentId:(NSString*)equipmentId;
///**
// *  更新设备上一次的维保时间
// *
// *  @param equipments    设备数组
// *  @param maintenceTime 维保时间
//  *  @param executorName 执行者姓名
// *
// *  @return 结果
// */
//- (BOOL)updateLastMaintenanceTimeWithEquipments:(NSArray*)equipments maintenceTime:(NSTimeInterval)maintenceTime executorName:(NSString*)executorName;
/**
 *  获取二维码中设备的类型、类型中包含的设备数
 *
 *  @param qrcodeId 二维码Id
 *
 *  @return 二维码类型设备数量模型数组
 */
- (NSArray*)qrcodeEquipmentInfos:(NSString*)qrcodeId;
/**
 *  获取二维码中设备的类型、类型中包含的设备数
 *
 *  @param qrcodeId        二维码Id
 *  @param equipmentTypeId 设备类型Id
 *
 *  @return 设备模型
 */
- (NSArray*)qrcodeEquipmentInfos:(NSString*)qrcodeId orLocationId:(NSInteger)locationId equipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  获取二维码中设备类型的设备
 *
 *  @param qrcodeId        二维码Id
 *  @param equipmentTypeId 设备类型Id
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentWithQrcodeId:(NSString*)qrcodeId orLocationId:(NSInteger)locationId equipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  获取二维码中所有的设备
 *
 *  @param qrcodeId        二维码Id
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentWithQrcodeId:(NSString*)qrcodeId;
/**
 *  获取二维码中所有的设备，且是同类型的设备的二维数组
 *
 *  @param qrcodeId        二维码Id
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentInNoQrcodeLedgerWithQrcodeId:(NSString*)qrcodeId;
/**
 *  获取locationId中所有的设备类型
 *
 *  @param locationId        位置Id
 @  param equipmentTypeId   设备类型Id
 *  @return 设备模型
 */
- (NSArray*)equipmentTypeArrayWithLocationId:(NSInteger)locationId AndEquipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  获取QrcodeId中所有的设备类型
 *
 *  @param QrcodeId        二维码Id
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentTypeArrayWithQrcodeId:(NSString*)qrcodeId;
/**
 *  获取locationId中所有的设备(二维数组)
 *
 *  @param locationId        位置Id
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentArrayWithLocationId:(NSInteger)locationId;
/**
 *  获取locationId中所有的设备(一维维数组)
 *
 *  @param locationId        位置Id
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentWithLocationId:(NSInteger)locationId;
/**
 *  根据搜索条件筛选设备(一维数组)
 *
 *  @param buildingId 楼盘id
 *  @param apartmentId 楼栋id
 *  @param floorId 楼层id
 *  @param locationId 位置id
 *  @param SubSystemTypeId 子系统id
 *  @param equipmentTypeId 设备类型id
 *  @param page 页数
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentsWithBuildingId:(NSString*)buildingId ApartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId locationId:(NSInteger)locationId eqipmentSubSystemType:(NSInteger)SubSystemTypeId equipmentTypeId:(NSInteger)equipmentTypeId page:(NSInteger)page;
/**
 *  根据搜索条件筛选设备(二维数组)
 *
 *  @param buildingId 楼盘id
 *  @param apartmentId 楼栋id
 *  @param floorId 楼层id
 *  @param locationId 位置id
 *  @param SubSystemTypeId 子系统id
 *  @param equipmentTypeId 设备类型id
 *  @param page 页数
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentArrayWithBuildingId:(NSString*)buildingId ApartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId locationId:(NSInteger)locationId eqipmentSubSystemType:(NSInteger)SubSystemTypeId equipmentTypeId:(NSInteger)equipmentTypeId page:(NSInteger)page;
/**
 *  根据搜索条件筛选设备，根据这个数组筛选设备类型
 *
 *  @param buildingId 楼盘id
 *  @param apartmentId 楼栋id
 *  @param floorId 楼层id
 *  @param locationId 位置id
 *  @param SubSystemTypeId 子系统id
 *  @param equipmentTypeId 设备类型id
 *  @param page 页数
 *
 *  @return 设备模型数组
 */
- (NSArray*)equipmentArrayWithBuildingId:(NSString*)buildingId ApartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId locationId:(NSInteger)locationId eqipmentSubSystemType:(NSInteger)SubSystemTypeId equipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  根据搜索条件筛选设备，返回YWQrcodeEquipmentInfo对象的一维数组
 *
 *  @param buildingId 楼盘id
 *  @param apartmentId 楼栋id
 *  @param floorId 楼层id
 *  @param locationId 位置id
 *  @param SubSystemTypeId 子系统id
 *  @param equipmentTypeId 设备类型id
 *  @param page 页数
 *
 *  @return YWQrcodeEquipmentInfo数组
 */
- (NSArray *)equipmentInfoArrayWithBuildingId:(NSString *)buildingId ApartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId locationId:(NSInteger)locationId eqipmentSubSystemType:(NSInteger)SubSystemTypeId equipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  获取locationId中所有的设备类型
 *
 *  @param locationId        位置Id
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentTypesWithLocationId:(NSInteger)locationId  orBuildingId:(NSString*)buildingId;
/**
 *  根据搜索条件查询设备数
 *
 *  @param buildingId 楼盘id
 *  @param apartmentId 楼栋id
 *  @param floorId 楼层id
 *  @param locationId 位置id
 *  @param SubSystemTypeId 子系统id
 *  @param equipmentTypeId 设备类型id
 *
 *  @return 设备模型
 */
- (NSInteger)equipmentCountWithBuildingId:(NSString*)buildingId ApartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId locationId:(NSInteger)locationId eqipmentSubSystemType:(NSInteger)SubSystemTypeId equipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  根据搜索条件查询二维码数
 *
 *  @param buildingId 楼盘id
 *  @param apartmentId 楼栋id
 *  @param floorId 楼层id
 *  @param locationId 位置id
 *  @param SubSystemTypeId 子系统id
 *  @param equipmentTypeId 设备类型id
 *
 *  @return 设备模型
 */
- (NSInteger)qrcodeCountWithBuildingId:(NSString*)buildingId ApartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId locationId:(NSInteger)locationId eqipmentSubSystemType:(NSInteger)SubSystemTypeId equipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  根据搜索条件筛选设备，返回根据locationId排序的二维数组
 *
 *  @param buildingId 楼盘id
 *  @param apartmentId 楼栋id
 *  @param floorId 楼层id
 *  @param locationId 位置id
 *  @param SubSystemTypeId 子系统id
 *  @param equipmentTypeId 设备类型id
 *  @param page 页数
 *
 *  @return 设备模型二维数组
 */
- (NSArray *)equipmentArrayOrderByLocationIdWithBuildingId:(NSString *)buildingId ApartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId locationId:(NSInteger)locationId eqipmentSubSystemType:(NSInteger)SubSystemTypeId equipmentTypeId:(NSInteger)equipmentTypeId page:(NSInteger)page;
///**
// *  获取设备的最新维保时间
// */
//- (void)requestLastMaintenanceTime;

/**
 *  获取二维码位置id
 *
 *  @param qrcodeId 二维码编号
 *
 *  @return 位置Id
 */
- (NSInteger)locationIdWithQrcodeId:(NSString*)qrcodeId;
#pragma mark - 设备的使用方法和范围
- (BOOL)updateEquipmentUseMenthodWithArray:(NSArray*)useMenthodArray;
- (NSTimeInterval)useMenthodMaxUpdateTime;
- (YWEquipmentUseMenthod*)useMenthodWithEquipmentTypeId:(NSInteger)equipmentTypeId;

- (BOOL)updateEquipmentUseRangeWithArray:(NSArray*)useRangeArray;
- (NSTimeInterval)useRangeMaxUpdateTime;
- (YWEquipmentUseRange*)useRangeWithEquipmentTypeId:(NSInteger)equipmentTypeId;
@end
